#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
const int N = 1050;
int arr[N], temp[N];
int z[N];
int n, k;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		scanf("%d%d", &n, &k);
		for (int i = 0; i < n; i++) {
			scanf("%d", &arr[i]);
			temp[i] = arr[i];
			z[i] = arr[i];
		}
		while (k--) {
			if (next_permutation(z, z + n) == -1) {
				for (int i = 0; i < n; i++) {
					arr[i] = temp[i];
				}
			}
			else {
				next_permutation(arr, arr + n);
				for (int i = 0; i < n; i++) {
					z[i] = arr[i];
				}
			}
		}
		for (int i = 0; i < n; i++) {
			printf("%d ", arr[i]);
		}
		printf("\n");
	}
	return 0;
}